package com.gxm.练习.模式.单例;

import lombok.SneakyThrows;
import org.junit.Before;
import org.junit.Test;

public class Demo {

    private Single single;
    @Before
    public void init(){
        single = Single.getSingle();
    }

    @Test
    public void test01() throws InterruptedException {
        try {
            ThreadDemo threadDemo1 = new ThreadDemo(2000);
            ThreadDemo threadDemo2 = new ThreadDemo(4000);
            threadDemo1.start();
            threadDemo2.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Thread.sleep(8000);

    }

    @Test
    public void test02() throws InterruptedException {
        single.getS("10", 3000);
    }
}


class ThreadDemo extends Thread{
    private Single single = Single.getSingle();
    private long sleep;

    public ThreadDemo(long sleep){
        this.sleep = sleep;
    }
    @Override
    public void run(){
        try {
            single.getS(String.valueOf(sleep), sleep);
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}